﻿cmake_minimum_required (VERSION 3.8)

project(strategy_api)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} $ENV{CXXFLAGS} -w")
add_definitions(-DLINUX -DBOOST_LOG_DYN_LINK)
add_definitions("-g -ggdb -O0 -fPIC")

set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ version selection")  # or 11, 14, 17, 20
set(CMAKE_CXX_STANDARD_REQUIRED ON)  # optional, ensure standard is supported

# 需要编译的 proto 文件
file (GLOB PROTO_SOURCE_FILES
    "${CMAKE_SOURCE_DIR}/protobuf/*.proto"
)
set(PROTOBUF_PROTOC_EXECUTABLE $ENV{HOME}/ficc_deps/bin/protoc)
set(PROTO_PATH    "${CMAKE_SOURCE_DIR}/protobuf/")
set(PROTO_CXX_OUT "${CMAKE_SOURCE_DIR}/protobuf/")
# 使用 protoc 处理 proto 文件
foreach(input_proto ${PROTO_SOURCE_FILES})
    get_filename_component(FILE_NAME ${input_proto} NAME_WE)
    set(OUTPUT_CXX_HEADER   "${PROTO_CXX_OUT}/${FILE_NAME}.pb.h")
    set(OUTPUT_CXX_SOURCE   "${PROTO_CXX_OUT}/${FILE_NAME}.pb.cc")
    list(APPEND OUTPUT_SOURCES_CXX ${OUTPUT_CXX_HEADER} ${OUTPUT_CXX_SOURCE})
endforeach()

add_custom_command(
    OUTPUT ${OUTPUT_SOURCES_CXX}
    COMMAND export LD_LIBRARY_PATH=$ENV{HOME}/ficc_deps/lib && ${PROTOBUF_PROTOC_EXECUTABLE} -I${PROTO_PATH} --cpp_out=${PROTO_CXX_OUT}  --proto_path=${PROTO_PATH} ${PROTO_SOURCE_FILES}
    DEPENDS ${PROTO_SOURCE_FILES}
    WORKING_DIRECTORY ${PROTO_PATH}
    COMMENT "Generate Cpp Protobuf Source Files"
)

set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/libs)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/libs)

include_directories(${CMAKE_SOURCE_DIR} ~/ficc_deps/include ${CMAKE_SOURCE_DIR}/protobuf)
link_directories(~/ficc_deps/lib)

# aux_source_directory(. SOURCE_FILES)
# add_executable(main main.cpp ${OUTPUT_SOURCES_CXX})
# target_link_libraries(main PUBLIC protobuf pthread dl util)

# add_executable(client client.cpp ${OUTPUT_SOURCES_CXX})
# target_link_libraries(client PUBLIC protobuf crypto ssl pthread dl util)

# add_executable(server server.cpp ${OUTPUT_SOURCES_CXX})
# target_link_libraries(server PUBLIC protobuf crypto ssl pthread dl util)

add_executable(interprocess_test interprocess_test10.cpp custom_data.cpp ${OUTPUT_SOURCES_CXX})
target_link_libraries(interprocess_test PUBLIC protobuf pthread dl util rt)
